package javamoney;

import org.javamoney.moneta.FastMoney;
import org.javamoney.moneta.Money;

import javax.money.CurrencyUnit;
import javax.money.Monetary;
import javax.money.MonetaryAmount;
import javax.money.convert.CurrencyConversion;
import javax.money.convert.ExchangeRate;
import javax.money.convert.ExchangeRateProvider;
import javax.money.convert.MonetaryConversions;
import java.util.Locale;

/**
 * Created by ZhuQianli on 2018/1/30.
 */
public class App {


    /**
     * https://my.oschina.net/VILLE/blog/1611920
     *
     * @param args
     */
    public static void main(String[] args) {


        CurrencyUnit USCurrencyUnit = Monetary.getCurrency(Locale.US);
        CurrencyUnit CNCurrencyUnit = Monetary.getCurrency(Locale.CHINA);

        Money money = Money.of(200, USCurrencyUnit);

        FastMoney fastMoney = FastMoney.of(100, USCurrencyUnit);

        System.out.println(fastMoney);

        ExchangeRateProvider exchangeRateProvider = MonetaryConversions.getExchangeRateProvider();

        ExchangeRate rate = exchangeRateProvider.getExchangeRate("EUR", "USD");

        System.out.println(rate);

        CurrencyConversion dollarConversion = MonetaryConversions.getConversion("USD");

        MonetaryAmount tenEuro = Money.of(10, "EUR");

        MonetaryAmount inDollar = tenEuro.with(dollarConversion);

        System.out.println(inDollar);
    }

}
